Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to match primary_role when roles are filtered #594

Merged
merged 3 commits into from
Nov 28, 2023

Conversation

mdkent
Copy link
Member

@mdkent mdkent commented Nov 25, 2023

Make an effort to match the primary_role from a list of specific roles.

eg: given a config like

primary_role: web_site2

servers:
  web_site1:
    traefik: true
    hosts:
    - 1.1.1.1
    - 1.1.1.2

  jobs_site1:
    hosts:
    - 1.1.1.3
    - 1.1.1.4

  web_site2:
    traefik: true
    hosts:
    - 2.1.1.1
    - 2.1.1.2

  jobs_site2:
    hosts:
    - 2.1.1.3
    - 2.1.1.4

and if we filter by site2:

$ bin/kamal lock release -d staging -r *_site2 -H
  INFO [366c0fe0] Running /usr/bin/env mkdir -p .kamal on 2.1.1.3   <-- oops! first jobs node

Things will run on the first role + first host in the specific roles array, which is a bit unexpected given the primary_role we requested.

With this change it'll make an effort to match the primary_role:

$ bin/kamal lock release -d staging -r *_site2 -H
  INFO [478deb96] Running /usr/bin/env mkdir -p .kamal on 2.1.1.1

Much nicer.

This also fixes a role filtered deploy issue we're seeing:

$ bin/kamal deploy -d staging -r *_sc_chi -H
<snip>
  INFO [5fba68d3] Running docker container ls --all --filter name=^healthcheck-foo-staging-a68cf68d02fc0922a2ee85a1d8c9d69af7fc4a39_uncommitted_d6efcf639bf13e59$ --quiet | xargs docker container rm on foo-staging-console-01
  INFO [5fba68d3] Finished in 0.323 seconds with exit status 123 (failed).
Releasing the deploy lock...
  Finished all in 124.8 seconds
  ERROR (SSHKit::Command::Failed): Exception while executing on host foo-staging-console-01: docker exit status: 125
docker stdout: Nothing written
docker stderr: docker: open .kamal/env/roles/foo-web_sc_chi-staging.env: no such file or directory.
See 'docker run --help'.

or

$ bin/kamal deploy -d staging -r console,web -H
<snip>
Releasing the deploy lock...
  Finished all in 85.0 seconds
  ERROR (SSHKit::Command::Failed): Exception while executing on host foo-staging-console-101: docker exit status: 125
docker stdout: Nothing written
docker stderr: docker: open .kamal/env/roles/foo-web-staging.env: no such file or directory.
See 'docker run --help'.

where kamal attempts to use the primary_role env on whatever role happens to come first.

This is less surprising than picking the first role and first host.
@mdkent mdkent requested a review from djmb November 25, 2023 01:58
mdkent and others added 2 commits November 25, 2023 12:47
Keeps us confusingly running things on the primary_host when nothing
matches.
Error out when roles or host filters don't match anything
@djmb djmb merged commit e3d8a2a into main Nov 28, 2023
6 checks passed
@djmb djmb deleted the match-primary-role-in-filters branch November 28, 2023 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants